package com.zdzx.common.config;

import javax.sql.DataSource;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ValidateDataSource implements ApplicationContextAware {

	private static ApplicationContext context;

	@Value("spring.datasource.username")
	private static String bbb;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		try {
			context = applicationContext;
			System.out.println(bbb + "----------------------------");
			DataSource dataSource = (DataSource) context.getBean("dataSource");
			dataSource.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}

	}

	public ApplicationContext getApplicationContext() {
		return context;
	}

}
